package com.yike.order.controller;

import com.yike.order.entity.RefundDetail;
import com.yike.order.service.RefundDetailService;
import lombok.extern.slf4j.Slf4j;
import com.yike.order.param.RefundDetailPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 订单退款详情表 控制器
 *
 * @author Sakura
 * @since 2024-09-04
 */
@Slf4j
@RestController
@RequestMapping("/refundDetail")
@Module("order")
@Api(value = "订单退款详情表API", tags = {"订单退款详情表"})
@ApiIgnore
public class RefundDetailController extends BaseController {

    @Autowired
    private RefundDetailService refundDetailService;

    /**
     * 添加订单退款详情表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加订单退款详情表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加订单退款详情表", response = ApiResult.class)
    public ApiResult<Boolean> addRefundDetail(@Validated(Add.class) @RequestBody RefundDetail refundDetail) throws Exception {
        boolean flag = refundDetailService.saveRefundDetail(refundDetail);
        return ApiResult.result(flag);
    }

    /**
     * 修改订单退款详情表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改订单退款详情表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改订单退款详情表", response = ApiResult.class)
    public ApiResult<Boolean> updateRefundDetail(@Validated(Update.class) @RequestBody RefundDetail refundDetail) throws Exception {
        boolean flag = refundDetailService.updateRefundDetail(refundDetail);
        return ApiResult.result(flag);
    }

    /**
     * 删除订单退款详情表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除订单退款详情表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除订单退款详情表", response = ApiResult.class)
    public ApiResult<Boolean> deleteRefundDetail(@PathVariable("id") Long id) throws Exception {
        boolean flag = refundDetailService.deleteRefundDetail(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取订单退款详情表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "订单退款详情表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "订单退款详情表详情", response = RefundDetail.class)
    public ApiResult<RefundDetail> getRefundDetail(@PathVariable("id") Long id) throws Exception {
        RefundDetail refundDetail = refundDetailService.getById(id);
        return ApiResult.ok(refundDetail);
    }

    /**
     * 订单退款详情表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "订单退款详情表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "订单退款详情表分页列表", response = RefundDetail.class)
    public ApiResult<Paging<RefundDetail>> getRefundDetailPageList(@Validated @RequestBody RefundDetailPageParam refundDetailPageParam) throws Exception {
        Paging<RefundDetail> paging = refundDetailService.getRefundDetailPageList(refundDetailPageParam);
        return ApiResult.ok(paging);
    }

}

